<?php
class Product_Model_ProductOptionValue
{
	protected $_table;
	public function __construct(){
		$this->_table = new Product_Model_DbTable_ProductOptionValue();
	}
	
	public function getDbTable(){
		return $this->_table;
	}
	
	public function getAdapter(){
		return $this->_table->getAdapter();
	}
	
	public function update($row,$productId,$poId){
		$where = $this->_table->getAdapter()->quoteInto("product_id = ?",$productId);
		$where .= $this->_table->getAdapter()->quoteInto(" and po_id = ?",$poId);
		return $this->_table->update($row,$where);
	}
	/**
	* ͨ���Ʒid��ѯ
	* @param int $productId
	* @param int $poId
	* @return zend_db_table_rowset
	*/
	public function getByProductId($productId,$poId = null){
		$where = $this->_table->select()->where("product_id = ?",$productId);
		if($poId != null){
			$where->where("po_id = ?",$poId);
		}
		return $this->_table->fetchAll($where);
	}
	
	public function deleteByProductId($productId){
		$where = $this->_table->getAdapter()->quoteInto("product_id = ?",$productId);
		return $this->_table->delete($where);
	}
	
	//查询
	public function getByCondition($p_id,$po_id,$poc_id){
		$where = $this->_table->getAdapter()->quoteInto(" product_id = ?",$p_id);
		$where .= $this->_table->getAdapter()->quoteInto(" and po_id = ?",$po_id);
		$where .= $this->_table->getAdapter()->quoteInto(" and poc_id = ?",$poc_id);
		return $this->_table->fetchAll($where)->toArray();
	}
	
	
	
	//修改
	public function modifyByCondition($row,$p_id,$po_id,$poc_id){
		$where =$this->_table->getAdapter()->quoteInto("product_id = ?",$p_id);
		$where .=$this->_table->getAdapter()->quoteInto(" and po_id = ?",$po_id);
		$where .=$this->_table->getAdapter()->quoteInto(" and poc_id = ?",$poc_id);
		return $this->_table->update($row,$where);
	}
	
	//删除
	public function deleteByCondition($p_id,$po_id,$poc_id){
		$where =$this->_table->getAdapter()->quoteInto(" product_id = ?",$p_id);
		$where .=$this->_table->getAdapter()->quoteInto(" and po_id = ?",$po_id);
		if(!empty($poc_id)){
			$where .=$this->_table->getAdapter()->quoteInto(" and poc_id not in(?)",$poc_id);
		}
		return $this->_table->delete($where);
	}
	
	//真删除
	public  function delete($productId){
		$where =$this->_table->getAdapter()->quoteInto(" product_id = ?",$productId);
		return $this->_table->delete($where);
	}
	
	
}